package edu.guet.server.service;

import edu.guet.server.mapper.TechSemMapper;
import edu.guet.server.mapper.UserMapper;
import edu.guet.server.model.Course;
import edu.guet.server.model.User;
import edu.guet.server.model.TecherCourse;
import edu.guet.server.model.dto.TeamTeacherDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TechSemService {
    @Autowired
    TechSemMapper techSemMapper;
    @Autowired
    UserMapper userMapper;
    /**
     * 添加教师创建学期课程表
     * @param course
     */
    public void addTechCourse(Course course) {
        TecherCourse t = new TecherCourse();
        t.setTech_id(course.getTech_id());
        t.setCourse_id(course.getCourse_id());
        techSemMapper.addTechCourse(t);
    }

    public void addTeamTeacher(TeamTeacherDTO teamTeacherDTO) {
        techSemMapper.addTeamTeacher(teamTeacherDTO);
    }
    /**
     * 查找老师
     * @param teamTeacherDTO
     */
    public TeamTeacherDTO findUserByUsernameorEmail(TeamTeacherDTO teamTeacherDTO) {
        User u=userMapper.findUserByNameorEmail(teamTeacherDTO.getPhone_num(),teamTeacherDTO.getEmail());
        teamTeacherDTO.setUser_id(u.getId());
        teamTeacherDTO.setImg_url(u.getImg_url());
        teamTeacherDTO.setUsername(u.getUsername());
        return teamTeacherDTO;
    }

    /**
     * 获得老师关联课堂的所有id
     * @return
     */
    public List<Integer> findsemesterIdsBytechId(Integer tech_id) {
        return techSemMapper.findsemesterIdsBytechId(tech_id);
    }

    /**
     * 根据课程id获取老师ids
     * @param cID
     * @return
     */
    public List<Integer> findtechIdsBycouId(Integer cID) {
        return techSemMapper.findtechIdsBysemId(cID);
    }

    /**
     * 根据老师的ids返回不同的老师信息
     * @param techIds
     * @return
     */
    public List<TeamTeacherDTO> findUsersByIds(List<Integer> techIds) {
        List<TeamTeacherDTO> tlist=new ArrayList<>();
        List<User> ulist=userMapper.findUsersByIds(techIds);
        for(int i=0;i<ulist.size();i++){
            TeamTeacherDTO teamTeacherDTO = new TeamTeacherDTO();
            teamTeacherDTO.copyUser(ulist.get(i));
            tlist.add(teamTeacherDTO);
        }
        return tlist;
    }

    public TecherCourse findcourseIdsBytechId(TeamTeacherDTO teamTeacherDTO) {
        return techSemMapper.findcourseIdsBytechId(teamTeacherDTO);
    }
}
